package com.sdtbu.ylgh.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.sdtbu.ylgh.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import com.sdtbu.ylgh.entity.DepartmentEntity;
import com.sdtbu.ylgh.service.DepartmentService;



/**
 * 科室信息表
 *
 * @author mzd
 * @email 1695165447@qq.com
 * @date 2021-03-13 17:53:04
 */
@CrossOrigin
@RestController
@RequestMapping("ylgh/department")
public class DepartmentController {
    @Autowired
    private DepartmentService departmentService;

    /**
     * 列表
     */
    @Cacheable(value = "department", key = "'list'")
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        System.out.println("department-list");
        List<DepartmentEntity> page = departmentService.listByMap(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("ylgh:department:info")
    public R info(@PathVariable("id") Long id){
		DepartmentEntity department = departmentService.getById(id);

        return R.ok().put("department", department);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("ylgh:department:save")
    public R save(@RequestBody DepartmentEntity department){
		departmentService.save(department);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("ylgh:department:update")
    public R update(@RequestBody DepartmentEntity department){
		departmentService.updateById(department);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("ylgh:department:delete")
    public R delete(@RequestBody Long[] ids){
		departmentService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
